//
//  MyTabbarViewController.m
//  CoolRollerSkating
//
//  Created by 谢伟康 on 15/11/9.
//  Copyright © 2015年 Coollang. All rights reserved.
//

#import "MyTabbarViewController.h"
#import "SportViewController.h"
#import "SportHistoryRecordViewController.h"
#import "CompetitionViewController.h"
#import "MyNavigationViewController.h"
#import "TrainViewController.h"
#import "UserCenterViewController.h"

@interface MyTabbarViewController ()

@end

@implementation MyTabbarViewController

#pragma mark - ViewLifeCircle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubViewController];
    [self customizeTabBarItems];
//    [self customizeMiddleTabbarItem];
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

#pragma mark - Private Method

- (void)setupSubViewController
{
    UIStoryboard *sportSb = [UIStoryboard storyboardWithName:@"Sport" bundle:nil];
    SportViewController *sportVC = [sportSb instantiateViewControllerWithIdentifier:@"SportViewController"];
    MyNavigationViewController *sportNav = [[MyNavigationViewController alloc] initWithRootViewController:sportVC];
    
    UIStoryboard *trainSb = [UIStoryboard storyboardWithName:@"Train" bundle:nil];
    TrainViewController *trainVC = [trainSb instantiateViewControllerWithIdentifier:@"TrainCenterViewController"];
    MyNavigationViewController *trainNav = [[MyNavigationViewController alloc] initWithRootViewController:trainVC];
    
//    UIStoryboard *rankSb = [UIStoryboard storyboardWithName:@"Competition" bundle:nil];
//    CompetitionViewController *rankVC = [rankSb instantiateViewControllerWithIdentifier:@"CompetitionViewController"];
//    MyNavigationViewController *rankNav = [[MyNavigationViewController alloc] initWithRootViewController:rankVC];
    
    // 新排行榜
    MyNavigationViewController *newRankNav = [[UIStoryboard storyboardWithName:@"Ranking" bundle:nil] instantiateInitialViewController];
    
    // 圈子
    MyNavigationViewController *pyqNav = [[UIStoryboard storyboardWithName:@"Find" bundle:nil] instantiateInitialViewController];
    
    UIStoryboard *userSb = [UIStoryboard storyboardWithName:@"UserCenter" bundle:nil];
    UserCenterViewController *userVC = [userSb instantiateViewControllerWithIdentifier:@"UserCenterViewController"];
    MyNavigationViewController *userNav = [[MyNavigationViewController alloc] initWithRootViewController:userVC];
    
//    self.viewControllers = @[sportNav,trainNav,newRankNav,pyqNav,userNav];
    self.viewControllers = @[sportNav,trainNav,newRankNav,userNav];
}

- (void)customizeTabBarItems
{
    //运动
    UITabBarItem *tabBarItem = [self.tabBar.items objectAtIndex:0];
    tabBarItem.title = NSLocalizedString(@"Sport.Statistics", nil);
    
    UIImage *unselectedImage = [UIImage imageNamed:@"tabbar_icon_sport_us"];
    UIImage *selectedImage = [UIImage imageNamed:@"tabbar_icon_sport"];
    
    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //训练
    tabBarItem = [self.tabBar.items objectAtIndex:1];
    tabBarItem.title = NSLocalizedString(@"Training", nil);
    
    unselectedImage = [UIImage imageNamed:@"tabbar_icon_training_us"];
    selectedImage = [UIImage imageNamed:@"tabbar_icon_training"];
    
    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //排行榜
//    tabBarItem = [self.tabBar.items objectAtIndex:2];
//    tabBarItem.title = NSLocalizedString(@"Ranking", nil);
//    
//    unselectedImage = [UIImage imageNamed:@"tabbar_icon_rank_us"];
//    selectedImage = [UIImage imageNamed:@"tabbar_icon_rank"];
//    
//    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 新排行
    tabBarItem = [self.tabBar.items objectAtIndex:2];
    tabBarItem.title = NSLocalizedString(@"Ranking", nil);
    unselectedImage = [UIImage imageNamed:@"tabbar_icon_rank_us"];
    selectedImage = [UIImage imageNamed:@"tabbar_icon_rank"];
    
    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 朋友圈
//    tabBarItem = [self.tabBar.items objectAtIndex:3];
//    tabBarItem.title = NSLocalizedString(@"Ranking", nil);
//    unselectedImage = [UIImage imageNamed:@"tabbar_icon_rank_us"];
//    selectedImage = [UIImage imageNamed:@"tabbar_icon_rank"];
//
//    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    //个人
    tabBarItem = [self.tabBar.items objectAtIndex:3];
    tabBarItem.title = NSLocalizedString(@"Me", nil);
    
    unselectedImage = [UIImage imageNamed:@"tabbar_icon_person_us"];
    selectedImage = [UIImage imageNamed:@"tabbar_icon_person"];
    
    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}

- (void)customizeMiddleTabbarItem
{
    self.tabBar.shadowImage = [[UIImage alloc] init];
    self.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_icon_background"];
    
    UITabBarItem *tabBarItem = [self.tabBar.items objectAtIndex:2];
    tabBarItem.title = @"";
    
    UIImage * unselectedImage = [UIImage imageNamed:@"tabbar_icon_sport_us"];
    UIImage * selectedImage = [UIImage imageNamed:@"tabbar_icon_sport"];
    
    [tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setSelectedImage: [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
//    [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
}


@end
